import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import '@/styles/footer.less'
import Loadding from '@/components/Loadding/index.vue'; // 导入加载动画组件
import { createPinia } from 'pinia';
import { createPersistedState } from 'pinia-plugin-persistedstate';
import i18n from './utils/i18n.js';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
// import VConsole from 'vconsole';
// const vConsole = new VConsole();

// 创建Vue应用实例
const app = createApp(App)
if(import.meta.env.DEV){
    window.baseUrl = import.meta.env.VITE_BASE_URL //开发环境
}else{
    window.baseUrl = '//'+window.location.hostname+"/game/public" //生产环境
}
app.config.globalProperties.$baseUrl = window.baseUrl
app.use(router)

const pinia = createPinia();
pinia.use(createPersistedState());
app.use(pinia);
app.use(i18n);
// 全局注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}

if(window.baseUrl == "http://192.168.110.244:8081/game/public"){
    window.hostUrl = 'http://localhost:5178/#';
}else{
    window.hostUrl = '//'+window.location.hostname+'/h5/#';
}

function getDeviceType() {
    const userAgent = navigator.userAgent || navigator.vendor || window.opera;
    console.log(userAgent);
    
    // 判断是否为 Android
    if (/android/i.test(userAgent) || /iPhone|iPad|iPod/i.test(userAgent) || /HUAWEI/i.test(userAgent) && /HarmonyOS/i.test(userAgent)) {
        return true;
    }else{
        return false
    }
}

function jump() {
    if( !window.location.hash.includes('playgame') 
        && 
        !window.location.hash.includes('paymentSuccess') 
        && 
        !window.location.hash.includes('paymentCancel') 
        && 
        !window.location.hash.includes('platform_pay')
        && 
        !window.location.hash.includes('fb_binding')
        && 
        !window.location.hash.includes('fb_login')
        && 
        !window.location.hash.includes('yh_login')
        && 
        !window.location.hash.includes('yh_binding')
        &&
        !window.location.hash.includes('gg_login')
        && 
        !window.location.hash.includes('gg_binding')
        && 
        !window.location.hash.includes('paymentPage')
        && 
        !window.location.hash.includes('SandSculptureMain')
    ){
            if(window.innerWidth < 1025 && window.baseUrl == "http://192.168.110.244:8081/game/public" && getDeviceType()){
                window.location.href = 'http://localhost:5178';
                console.log('跳转本地移动端链接');
            }
            
            if(window.innerWidth < 1025 && window.baseUrl !== "http://192.168.110.244:8081/game/public" && getDeviceType()){
                window.location.href = '//'+window.location.hostname+'/h5/#';
                console.log('跳转测试移动端');
            }
    }
}
jump()

// 添加事件监听器，当窗口大小变化时触发
// window.addEventListener('resize', function() {
//     jump()
// });

// 注册加载动画组件
app.component('Loadding', Loadding); 


app.mount('#app')